package paa.simulator;

import java.util.Random;

public class RandomNumberGenerator {

	private static RandomNumberGenerator instance = null;
	
	private Random random;
	
	private RandomNumberGenerator(int seed) {
		this.random = new Random(seed);
	}
	
	private RandomNumberGenerator() {
		this.random = new Random();
	}
	
	public static RandomNumberGenerator buildInstance(int seed) {
		if (instance != null) {
			throw new RuntimeException("Already Built");
		}
		
		instance = new RandomNumberGenerator(seed);
		return instance;
	}
	
	public static RandomNumberGenerator buildInstance() {
		if (instance != null) {
			throw new RuntimeException("Already Built");
		}
		
		instance = new RandomNumberGenerator();
		return instance;
	}

	public static RandomNumberGenerator getInstance() {
		if (instance == null) {
			throw new RuntimeException("Not Built");
		}
		
		return instance;
	}
	
	public double nextDouble() {
		return this.random.nextDouble();
	}
	
	public double nextDouble(double min, double max) {
		double i = nextDouble(max - min);
		return min + i;
	}

	private double nextDouble(double d) {
		return random.nextDouble() * d;
	}

	public int nextInt() {
		return random.nextInt();
	}
	
	public int nextInt(int n) {
		return random.nextInt(n);
	}
	
	public int nextInt(int min, int max) {
		int i = nextInt(max - min);
		return min + i;
	}
}
